
package editeur;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;

import javax.swing.*;

public class Fenetre extends JFrame{
	private PanneauImage panIm;
	private Vector<PanneauImageGrille> panIG;
	private PanneauMenu panMe;
	private Album albCourant;
	private boolean modePanIm;
	private int tIm,numIm;
	private int px,py;
	
	//Getters and Setters
	public Album getAlbCourant() {
		return albCourant;
	}

	public void setAlbCourant(Album albCourant) {
		this.albCourant = albCourant;
	}

	public PanneauImage getPanIm() {
		return panIm;
	}

	public void setPanIm(PanneauImage panIm) {
		this.panIm = panIm;
	}

	public PanneauMenu getPanMe() {
		return panMe;
	}

	public void setPanMe(PanneauMenu panMe) {
		this.panMe = panMe;
	}

	public Vector<PanneauImageGrille> getPanIG() {
		return panIG;
	}

	public void setPanIG(Vector<PanneauImageGrille> panIG) {
		this.panIG = panIG;
	}

	public boolean isModePanIm() {
		return modePanIm;
	}

	public void setModePanIm(boolean modePanIm) {
		this.modePanIm = modePanIm;
	}
	
	public int gettIm() {
		return tIm;
	}

	public void settIm(int tIm) {
		this.tIm = tIm;
	}

	public int getNumIm() {
		return numIm;
	}

	public void setNumIm(int numIm) {
		this.numIm = numIm;
	}

	public int getPx() {
		return px;
	}

	public void setPx(int px) {
		this.px = px;
	}

	public int getPy() {
		return py;
	}

	public void setPy(int py) {
		this.py = py;
	}

	//Constructeurs
	
	/**
	 * Constructeur de fenetre                       
	 */
	public Fenetre(){
		this.setTitle("Album photo personnel");
		this.setSize(350,350);
		this.setBackground(Color.white);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		modePanIm=false;
		albCourant=new Album();
		tIm=100;
		numIm=0;
		
		//Mode grande Images
		if(isModePanIm())
		{
			panIm= new PanneauImage(this);
			panMe= new PanneauMenu(this);
		
			add(panIm,BorderLayout.CENTER);
			add(panMe,BorderLayout.NORTH);
		}
		else//Mode petite images
		{
			panMe= new PanneauMenu(this);
			add(panMe,BorderLayout.NORTH);
			px=25;
			py=60;
			panIG=new Vector<PanneauImageGrille>();
			this.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent e) {
					for (Photo p:albCourant.getAlbum()){
						if (true);
					}
				}
			});

		}
		
		albCourant.afficheAlbum();
	}
	
	//Methodes
	/**
	 * Modifie la position future de l'image 
	 * 
	@param  f Fenetre sur laquelle il faut modifier le coordonnée                          
*/
	public void modPos(Fenetre f)
	{
		System.out.println("fut im x "+(f.getPx()+f.gettIm())+" -- width fene = "+f.getWidth());
		if((f.getPx()+f.gettIm())>f.getWidth())
		{
			if((f.getPy()+f.gettIm())>f.getHeight())
			{
				JOptionPane.showMessageDialog(null,"Il n'y a plus de place !");
			}
			else
			{
				f.setPy(f.getPy()+f.gettIm());
				f.setPx(25);
			}
		}
		else
			f.setPx(f.getPx()+f.gettIm());
		System.out.println("im x "+(f.getPx())+" -- width fene = "+f.getWidth());
		//System.out.println(" -- height fene = "+f.getHeight()+" -- width fene = "+f.getWidth());
	}
	
	/**
	 * Affiche les parametres de position de la fenetre courante 
	 * 
	@param  x Position x  
	@param  y Position y                        
*/
	public void affPos(int x,int y){
		System.out.println("PosX = "+x+" -- PosY = "+y);
	}
	/**
	 * Mise a jour des image de la fenetre 
	 * 
	@param  f Fenetre sur laquelle il faut modifier le coordonnée                          
*/
	public void majPanneaux(Fenetre f){
		for (int i=0;i<f.getAlbCourant().getAlbum().size();i++)
		{
			f.add(f.getPanIG().elementAt(i));
		}
		
	}
   //Main
	public static void main(String args[]){
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
            UIManager.put("swing.boldMetal", Boolean.FALSE);
            Fenetre f=new Fenetre();
            }
        });
	}
}

